package ZtlApi;

import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.storage.StorageManager;
import android.util.Log;

import androidx.annotation.RequiresPermission;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;


public class ZtlManagerHisi extends ZtlManager {


    //显示-设置屏幕方向 传入0 90 180 270
    @Override
    public void setDisplayOrientation(int rotation) {
        //转发到系统实现，以便正确修改ubootlogo
        setSystemProperty("persist.ztl.hwrotation", Integer.toString(rotation));
        reboot(1);
    }


    @Override
    public int getDisplayCount() {//海思只有一个屏幕
        return 1;
    }

    //系统-打开/关闭导航栏状态栏
    @Override
    public void openSystemBar(boolean bOpen) {
        if (mContext == null) {
            Log.e(TAG, "上下文为空,不执行");
            return;
        }
        Intent systemBarIntent = new Intent("com.ztl.action.systembar");
//        systemBarIntent.setPackage("com.android.systemui");       //因为framework 也要处理 所以不能指定包名接收
        systemBarIntent.putExtra("enable", bOpen);
        systemBarIntent.putExtra("skip_permission", true);
        mContext.sendBroadcast(systemBarIntent);
    }

    //系统-获取当前导航栏状态 显示还是隐藏
    @Override
    public boolean isSystemBarOpen() {
        String state = getSystemProperty("persist.ztl.systembar", "true");
        return Boolean.valueOf(state);
    }

    @Override
    public int gpioStringToInt(String port) {

        if (port.contains("GPIO") == false) {
            Log.e(TAG, "传入参数错误,请传入GPIO0_2之类的，实际以规格书为准");
            return -1;
        }
        try {
//        GPIO0_2,GPIO11_2
//        gpiochip11: GPIOs 416-423,
//        gpiochip0: GPIOs 504-511,
            int A = Integer.parseInt(port.substring(4,port.indexOf("_")));
            int B = Integer.parseInt(port.substring(port.indexOf("_")+1));

//        int C = port.charAt(7);
            int value = 511-(A*8)-(8-B-1);
//            511>>>0>>>0<<<<
//            System.out.println(value+">>>"+A+">>>"+B+"<<<<");
            if (value<416&&value>511){
                Log.e(TAG, "传入参数错误,请传入GPIO0_2之类的，实际以规格书为准");
                return -1;
            }
            return value;

//        return get905d3GpioValue(port);
        } catch (NumberFormatException e) {
            Log.e(TAG, "传入参数错误,请传入GPIO0_2之类的，实际以规格书为准");
            return -1;
        }
    }

}
